/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue.basic.reader.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import com.feiyue.basic.reader.pojo.Content;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ContentDao extends Dao {
	private static final String COMPERE = "content";

	public ContentDao(Context paramContext) {
		super(paramContext);
		this.db.setTableName("content");
	}

	private List<Content> getList(Cursor paramCursor) {
		ArrayList localArrayList = new ArrayList();
		if (paramCursor != null)
			paramCursor.moveToFirst();
		while (true) {
			if (paramCursor.isAfterLast()) {
				paramCursor.close();
				return localArrayList;
			}
			Content localContent = new Content();
			localContent.setId(paramCursor.getString(0));
			localContent.setCid(paramCursor.getString(1));
			localContent.setTitle(paramCursor.getString(2));
			localContent.setNid(paramCursor.getString(3));
			localContent.setPath(paramCursor.getString(4));
			localContent.setIcon(Integer.valueOf(paramCursor.getInt(5)));
			localArrayList.add(localContent);
			paramCursor.moveToNext();
		}
	}

	public void delete(long paramLong) {
		this.db.delete(paramLong);
	}

	public String getApi(String paramString, long paramLong) {
		return paramString + "_" + paramLong;
	}

	public List<Content> getList() {
		return getList(this.db.query(new String[] { "id", "cid", "title",
				"nid", "path", "icon" }, null, null, null, null, null));
	}

	public List<Content> getList(String paramString) {
		return getList(this.db.query(new String[] { "id", "cid", "title",
				"nid", "path", "icon" }, "path = ?",
				new String[] { paramString }, null, null, null));
	}

	public List<Content> getListByNid(String paramString) {
		return getList(this.db.query(new String[] { "id", "cid", "title",
				"nid", "path", "icon" }, "nid = ?",
				new String[] { paramString }, null, null, null));
	}

	public void save(Content paramContent) {
		List localList = getList(paramContent.getPath());
		ContentValues localContentValues = new ContentValues();
		if (localList.size() == 0) {
			localContentValues.put("id", paramContent.getId());
			localContentValues.put("cid", paramContent.getCid());
			localContentValues.put("nid", paramContent.getNid());
			localContentValues.put("path", paramContent.getPath());
			localContentValues.put("title", paramContent.getTitle());
			localContentValues.put("icon", paramContent.getIcon());
			this.db.insert(localContentValues);
			return;
		}
		localContentValues.put("cid", paramContent.getCid());
		localContentValues.put("nid", paramContent.getNid());
		localContentValues.put("path", paramContent.getPath());
		localContentValues.put("title", paramContent.getTitle());
		localContentValues.put("icon", paramContent.getIcon());
		this.db.update(Integer.valueOf(paramContent.getId()).intValue(),
				localContentValues);
	}

	public void save(List<Content> paramList) {
		Iterator localIterator = paramList.iterator();
		while (true) {
			if (!(localIterator.hasNext()))
				return;
			save((Content) localIterator.next());
		}
	}
}